<?php foreach ($edit_data as $key): ?>
<form class="form-horizontal" id="glEditForm">
	<div class="ibox float-e-margins">
		<div class="ibox-title" style="border: none;">
			<h5 style="color: #00afef"><i>Edit GL Accoutnts</i></h5>
				<div class="ibox-tools add">
					<button class="btn btn-primary btn-sm save-btn-tab">Save</button>
					<a id="cancel_edit" class="btn-outline btn btn-info btn-sm cancel-btn-tab" >Cancel</a>
				</div>
		</div>
		<div class="ibox-content">
				<div class="form-group"> <label class="col-lg-4 control-label">Company</label>
					<div class="col-lg-4">
						<input readonly type="text" name="gl_company_e" value="<?php echo $key->company_name; ?>" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-lg-4 control-label">Code</label>
					<div class="col-lg-5">
						<input readonly type="text" name="gl_code_e" value="<?php echo $key->acct_code; ?>" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-lg-4 control-label">Name</label>
					<div class="col-lg-5">
						<input value="<?php echo $key->acct_name; ?>" type="text" name="gl_name_e" class="form-control">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-4 control-label">Type</label>
					<div class="col-sm-4">
						<select disabled id="gl_type_select_e" class="form-control m-b" name="gl_type_e">
							<option value="">Select</option>
							<?php foreach ($glLookups as $lookup_type) {if ($lookup_type->lookup_type == "GL_ACCOUNT_TYPE") {?>
							 <option value="<?php echo $lookup_type->lookup_code; ?>"  <?php echo ($lookup_type->lookup_code == $key->acct_type ? "selected" : ""); ?>><?php echo $lookup_type->meaning; ?></option>
							 <?php }}
?>
						</select>
					</div>
				</div>
				<input type="hidden" name="account_id" value="<?php echo $key->account_id; ?>">
				<div class="form-group">
					<label class="col-sm-4 control-label">Sub-Type</label>
					<div class="col-sm-4">
						<select class="form-control m-b" name="gl_sub_type_e">
							<option value="">Select</option>
							<?php foreach ($glLookups as $lookup_type) {if ($lookup_type->lookup_type == "GL_ACCOUNT_SUB_TYPE") {?>
							<option value="<?php echo $lookup_type->lookup_code; ?>" <?php echo ($lookup_type->lookup_code == $key->sub_type ? "selected" : ""); ?>><?php echo $lookup_type->meaning; ?></option> <?php }}
?>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-lg-4 control-label">Enable</label>
					<div class="col-lg-1">
						<input type="checkbox" value="ok" name="gl_enabled_e" class="i-checks" <?php echo ($key->enable_flag == 'Y' ? 'checked' : ''); ?>>
					</div>
				</div>
			</form>
		</div>
	</div>
<?php endforeach;?>
	<script type="text/javascript">
	$(document).ready(function() {
		$('select').chosen({width: '100%'});
		$('#glEditForm').data('serialize',$('#glEditForm').serialize());
		$('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green'
        });

        $("#glEditForm").validate({
                 rules: {
                     gl_name_e: {
                        required: true
                     },
                     gl_sub_type_e: {
                     	required : true
                     },
                     gl_type_e: {
                        required: true
                     }
                 },
                 submitHandler: function(form){
                    $.ajax({
	                    url:"<?php echo base_url($this->session->userdata('forajax') . '/edit_Account'); ?>",
	                    method:'post',
	                    data:$('#glEditForm').serialize(),
	                    dataType:'json',
	                    success: function (data) {
	                         if(data.err == 1){
		                    	notifymsg('danger',data.msg);
		                    }else{
		                        $('#edit-link').remove();
		                        $('#edit').remove();
		                        $('#tab-list-2 a:first').tab('show');
		                        $('#count_edit').val('0');
		                        notifymsg('success','<b>Success</b>: Data Saved.');
		                    }
	                    },
	                    beforeSend: function(){

	                    }
	                });
                 }
        });
		function alert_cancel(){
		            if($('#glEditForm').serialize()!=$('#glEditForm').data('serialize')){
		                swal({
                              title: "Are you sure?",
                              text: "Your work will not be save",
                              type: "warning",
                              showCancelButton: true,
                              confirmButtonColor: "#DD6B55",
                              confirmButtonText: "Leave",
                              cancelButtonText: "Stay",
                              closeOnConfirm: true,
                              closeOnCancel: true },
                          function (isConfirm) {
                              if (isConfirm) {
                                  close_edit(); active_search();
                                  notifymsg("hide","hide");
                              } else {
                                  swal("Cancelled");
                              }
                          });
		                }else{
		                close_edit(); active_search();
		                notifymsg("hide","hide");
		            }
		        }
		        $('#cancel_edit').click(function(){
		            alert_cancel();
		        });
		      $('#editX').click(function(){
		            alert_cancel();
		      });
	});
	</script>